// pages/bodytest/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgli:[
      'https://zhongkexiangjiu.cn//zkxj/basic/down/image?imageKey=ecefd8d3-04e8-46da-834c-fba7459151db.png','https://zhongkexiangjiu.cn//zkxj/basic/down/image?imageKey=238c7915-425e-426f-bc1c-fb4d1ea3f63a.png',
      'https://zhongkexiangjiu.cn//zkxj/basic/down/image?imageKey=7719221c-595a-46e7-9b55-80d2d67f5bdc.png',
      'https://zhongkexiangjiu.cn//zkxj/basic/down/image?imageKey=39101269-0379-4959-994f-d5c5c6b988a9.png'
    ],
    fromdata:[],
    num:0,
    banum:0,
    huand:0,
    //判断当前是否选择
    istr:0,
    daarr:[],
    username:'',
    sexd:'',
    year:'',
    telphone:'',
    residence:'',
    //血压
    bloodpressure:'',
    //血氧
    bloodoxygen:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options);
    this.setData({
      username:options.username,
      sexd:options.sexd,
      year:options.year,
      telphone:options.telphone,
      residence:options.residence
    })
console.log(Math.floor(Math.random() * 4));
this.getwod()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },
getwod(){
  
  wx.request({
    url: app.globalData.url+'/zkxj/body/problem',
    data: {
    
    },
    method: 'GET',
    header: {
      'content-type': 'application/json',
        'token':wx.getStorageSync('token')
    },
    success: (res) => {
      console.log(res.data);
      this.data.fromdata=res.data.data
      this.setData({
        fromdata:res.data.data
      })
    },
    })
},
onChange(e){
console.log(e.detail);
this.setData({
  istr:e.detail
})
},
//点击加减题号
handletoaddw(){
  if(this.data.num<47){
    this.setData({
    num:this.data.num+1,
    banum:Math.floor(Math.random() * 4),
    huand:parseInt((this.data.num+2)/48*100),
    })
    // console.log(this.data.fromdata[this.data.num-1]);
//将选择的数组push到对象里面
    this.data.fromdata[this.data.num-1].answer=this.data.istr
    // console.log(this.data.fromdata[this.data.num-1]);
    //将选着的数据push到数组
this.data.daarr.push(this.data.fromdata[this.data.num-1]);
console.log(this.data.daarr);
this.setData({
  istr:0
})

  }
},
handlequese(){
  wx.request({
    url: app.globalData.url+'/zkxj/body/detection',
    data: {
      "address":this.data.residence,
      "age": this.data.year,
      "data": this.data.daarr,
      "phone": this.data.telphone,
      "sex": this.data.sexd,
      "userId":wx.getStorageSync('userId'),
      "userName": this.data.username

        },
    method: 'post',
    header: {
      'content-type': 'application/json',
        'token':wx.getStorageSync('token')
    },
    success: (res) => {
      console.log(res);
      if(res.data.code==0){
        wx.navigateTo({
          url: `/pages/result/index?detectionId=${res.data.data.detectionId}` 
      })
      }
    },
    })
},
handletodel(){
  if(this.data.num>0){
    this.setData({
    num:this.data.num-1,
    banum:Math.floor(Math.random() * 4)
    })
    this.data.daarr.pop();
  }
  console.log(this.data.daarr);
},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})